import nested_gen
import numpy
class eco_mat_gen:
    """OVERVIEW: this class represents presence/absence data
    DATA FIELDS: 
               pres_abs, a numpy array for the presence/absence data 
               params, a dictionary of statistical parameters that 
               the matrix should include
    """
    def __init__(self, parameters):
        #self.pres_abs = nested_gen.nest(parameters['sites'],
         #                               parameters['species'],
          #                              parameters['fill'], 
           #                             parameters['temp'])
        self.pres_abs = numpy.zeros((parameters['sites'],parameters['species']))
        self.params = parameters

    def print_to_file(self, file_name, print_option):
        """OVERVIEW: prints the matrix and parameters to file_name in the 
                  format specifies by print_option
        PARAMETERS: 
                  file_name, the name of the file to print to
                  print_option, the format 
        NOTES: currently the date is printed in the following format
               # parameter name:  parameter value
               followed by a tab delimited matrix
        """
        f = open(file_name,'w')

        for keys in self.params.keys():
            f.write("# "+str(keys)+":  "+str(self.params[keys])+"\n")
        for i in range(self.params['sites']):
            line = ""
            for j in range(self.params['species']):
                line = line + str(int(self.pres_abs[i,j])) + "\t" 
            f.write(line+"\n")
        f.close()
